package top.szhome.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.szhome.framework.starter.db.support.SimpleServiceImpl;
import top.szhome.system.convert.UserRoleConverter;
import top.szhome.system.dto.UserRoleDTO;
import top.szhome.system.entity.RoleMenu;
import top.szhome.system.entity.UserRole;
import top.szhome.system.mapper.UserRoleMapper;
import top.szhome.system.service.UserRoleService;
import top.szhome.system.vo.UserRoleVO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户角色 服务实现
 *
 * @author 唐加利
 * @date 2023/07/31
 **/
@AllArgsConstructor
@Service
@Slf4j
public class UserRoleServiceImpl extends SimpleServiceImpl<UserRoleMapper, UserRoleConverter, UserRoleDTO, UserRole, UserRoleVO> implements UserRoleService {

    @Override
    public List<Long> getRolesOfUser(Long userId) {
        List<UserRole> roles = list(Wrappers.lambdaQuery(UserRole.class).eq(UserRole::getUserId, userId));
        return roles.stream().map(UserRole::getRoleId).collect(Collectors.toList());
    }
}
